/* package com.wms.controller;

import com.wms.common.JwtUtils;
import com.wms.common.Result;
import com.wms.entity.User;
import com.wms.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    @CrossOrigin
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        log.info("用户登录:{}", user);
        User u = userService.login(user);

        //登录成功，生成令牌，下发令牌
        if(u != null){
            //生成令牌
            Map<String,Object> claims = new HashMap<>();
            claims.put("id", u.getId());//用户id
            claims.put("no", u.getNo());//用户账号
            claims.put("name", u.getName());//用户名称

            String jwt = JwtUtils.generateJwt(claims);//生成令牌
            log.info("下发令牌:{}", jwt);
            return Result.suc(jwt);
        }

        //登录失败,返回失败信息
        return Result.fail();
    }

}

 */